package ModelLayer;

import java.util.*;
/**
 * Write a description of class Loan here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Loan
{
    private String loanID;
    private String borrowDate;
    private int period;
    private String personID;
    private String copySerialNumber;
    private boolean isLending;
    private PersonContainer personCont;
    
    public Loan(String loanID, String borrowDate, String personID, String copySerialNumber)
    {
        personCont = PersonContainer.getInstance();
        this.loanID = loanID;
        this.borrowDate = borrowDate;
        period = 7;
        this.personID = personID;
        this.copySerialNumber = copySerialNumber;
        isLending = true;
    }
    
    public void setId(String id)
    {
        this.loanID = loanID;
    }
    
    public void setBorrowDate(String borrowDate)
    {
        this.borrowDate = borrowDate;
    }
    
    public void setPersonID(String personID)
    {
        this.personID = personID;
    }
    
    public void setCopySerialNumber(String copySerialNumber)
    {
        this.copySerialNumber = copySerialNumber;
    }
    
    public String getId()
    {
        return loanID;
    }
    
    public String getBorrowDate()
    {
        return borrowDate;
    }
    
    public int getPeriod()
    {
        return period;
    }
    
    public String getPersonID()
    {
        return personID;
    }
    
    public String getSerialNumber()
    {
        return copySerialNumber;
    }
    
    public String isLending()
    {
        String result="";
        if(isLending = true)
        {
            result = "Loan in action.";
        }
        else
        {
            result = "Loan completed.";
        }
        return result;
    }
    
    public String getPerson()
    {
        String resultName="";
        int index = 0;
        boolean found = false;
        while(index < personCont.getPersonList().size() && !found)
        {
            if(personCont.getPersonList().get(index).getId().equals(personID))
            {
                found = true;        
            }
            else
            {
                index++;
            }
        }
        if(found == true)
        {
            resultName = personCont.getPersonList().get(index).getName();
        }
        return resultName;
    }
}
